/* 
 * Copyright (C) 2012 UTSChedule
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package utsc.apps.utschedule.ui.activities.adapters;

import java.util.List;

import utsc.apps.utschedule.R;
import utsc.apps.utschedule.classes.ForecastResult;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * A list adapter to show the list of {@link ForecastResult forecast results}.
 *
 */
public class ForecastResultAdapter extends ArrayAdapter<ForecastResult> {

	public ForecastResultAdapter(Context context, int textViewResourceId,
			List<ForecastResult> objects) {
		super(context, textViewResourceId, objects);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView==null) {
			convertView=LayoutInflater.from(getContext()).inflate(R.layout.forecast_list_item, null);
			holder=new ViewHolder();
			holder._txtName=(TextView) convertView.findViewById(R.id.frm_txt_name);
			holder._txtCurrentMark=(TextView) convertView.findViewById(R.id.frm_txt_current_mark);
			holder._txtForecastedMark=(TextView) convertView.findViewById(R.id.frm_txt_forecast_mark);
			convertView.setTag(holder);
		}else {
			holder=(ViewHolder) convertView.getTag();
		}
		ForecastResult forecastResult=getItem(position);
		holder._txtName.setText(forecastResult.toString());
		holder._txtCurrentMark.setText(forecastResult.get_currentMark());
		holder._txtForecastedMark.setText(forecastResult.get_forecastedMark());
		return convertView;
	}
	
	private static class ViewHolder{
		TextView _txtName;
		TextView _txtCurrentMark;
		TextView _txtForecastedMark;
	}
}
